package com.nisco.dms.entity;

import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.MappedSuperclass;
import javax.persistence.OneToOne;

import org.hibernate.annotations.GenericGenerator;

import com.nisco.dms.shiro.ShiroDbRealm;
import com.nisco.dms.util.DateTools;

/*
 *  Copyright : 江苏金恒信息科技有限公司 NISCO
 *  Author : Jiang Bin(860012)
 *  System : 系统说明
 *  Target : 功能说明
 *  Create : 2013-4-16 下午1:53:25
 *  Update : 2013-4-16 下午1:53:25
 */

@MappedSuperclass
public abstract class CoreEntity {

	// 获取当前登录用户信息
	public static ShiroDbRealm.ShiroUser shiroUser = null;

	@Id
	@GenericGenerator(name = "idGenerator", strategy = "uuid")
	// 这个是hibernate的注解
	@GeneratedValue(generator = "idGenerator")
	// 使用uuid的生成策略
	protected String id; // 主键，采取uuid生成策略

	@OneToOne
	@JoinColumn(name = "companyId")
	protected Company company; // 创建人对应公司

	/*
	 * 暂不考虑部门、用户授权
	 * 
	 * @OneToOne(fetch = FetchType.LAZY)
	 * 
	 * @JoinColumn(name = "grantDeptId") protected Dept grantDept; //创建人对应部门
	 * 
	 * @OneToOne(fetch=FetchType.LAZY)
	 * 
	 * @JoinColumn(name="grantUserId") protected User grantUser; //创建者
	 */
	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "createUserId",updatable=false)
	protected User createUser; // 创建者

	@OneToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "updateUserId")
	protected User updateUser; // 修改日期

	@Column(updatable=false)
	protected String createDateTime; // 创建日期

	@Column()
	protected String updateDateTime; // 修改日期

	@Column()
	private Integer intIsDelete = 0; // 是否为删除，初始为0

	@Column()
	private Integer intIsActive = 1; // 是否为激活，初始位1

	public CoreEntity() {
		try {
			if (shiroUser != null) {
				this.updateUser = shiroUser.getUser();
				this.company = shiroUser.getCompany();
				this.updateDateTime = DateTools.getFullNowDateTime("yyyy-MM-dd HH:mm:ss");
			} else {
				this.updateUser = null;
				this.updateDateTime = null;
			}
		} catch (Exception e) {
			System.out.println("初始化创建者失败：" + e);
		}
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	/*
	 * public Dept getGrantDept() { return grantDept; }
	 * 
	 * 
	 * public void setGrantDept(Dept grantDept) { this.grantDept = grantDept; }
	 * 
	 * 
	 * 
	 * public User getGrantUser() { return grantUser; }
	 * 
	 * 
	 * public void setGrantUser(User grantUser) { this.grantUser = grantUser; }
	 */
	public User getCreateUser() {
		return createUser;
	}

	public void setCreateUser(User createUser) {
		this.createUser = createUser;
	}

	public User getUpdateUser() {
		return updateUser;
	}

	public void setUpdateUser(User updateUser) {
		this.updateUser = updateUser;
	}

	public String getCreateDateTime() {
		return createDateTime;
	}

	public void setCreateDateTime(String createDateTime) {
		this.createDateTime = createDateTime;
	}

	public String getUpdateDateTime() {
		return updateDateTime;
	}

	public void setUpdateDateTime(String updateDateTime) {
		this.updateDateTime = updateDateTime;
	}

	public Integer getIntIsDelete() {
		return intIsDelete;
	}

	public void setIntIsDelete(Integer intIsDelete) {
		this.intIsDelete = intIsDelete;
	}

	public Integer getIntIsActive() {
		return intIsActive;
	}

	public void setIntIsActive(Integer intIsActive) {
		this.intIsActive = intIsActive;
	}

}
